package edu.Test;

import java.util.Scanner;

public class test15 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int[] n = new int[t];
        String[] s=new String[t];
        sc.nextLine();
        for (int i=0;i<t;++i){
            n[i]=sc.nextInt();
            sc.nextLine();
            s[i]=sc.nextLine();
        }

        int[] num=new int[t];
        int[] money=new int[t];
        for (int i=0;i<t;++i){


            for (int j=0;j<n[i];++j){
                int cur=s[i].charAt(j)-'0';
                if (cur==0){
                    if (money[i]!=0){
                        money[i]--;
                        num[i]++;
                    }
                }else if (cur==1){
                    if (money[i]>=s[i].length()-j){
                        num[i]++;
                        money[i]--;
                    }else {
                        money[i]++;
                    }
                }else if (cur==2){
                    num[i]++;
                }else if (cur==3){
                    num[i]++;
                }

            }

        }

        for (int i=0;i<t;++i){
            System.out.println(num[i]);
        }

    }
}
